--[[
@mod marker (cmd)
]]
local Command = require "command"
local lume = require "lib.lume"
return Command("marker", {

	{"new", function (name, x, y)
		local x, y = tonumber(x) or Sled.grid.tx or 0, tonumber(y) or Sled.grid.ty or 0
		if not Sled.current_map then 
			return "You need to create a map first before using markers"
		end
		if not name then return "no name given" end
		return Sled.current_map:marker_add(name, x, y)
	end
	},
	
	{"list", function ()
		if not Sled.current_map then 
			return "You need to create a map first before using markers"
		end
		return Sled.current_map:markers_list ()
	end,
	},
	
	{"discard", function (_name)
		if _name == "all" then 
			Sled.current_map.markers = {} 
			pl.pretty.dump(Sled.current_map)
			return "Discarded all markers"
		end
		if not Sled.current_map or 
					not Sled.current_marker or
					not Sled.current_layer then return "no marker to discard" end
		local m = _name and Sled.current_map:marker_get(_name) or Sled.current_marker
		if not m then return "marker not found" end
		lume.remove(Sled.current_map.markers, m)
		return "Marker " .. m.name .. " removed"
	end
	}

})
